package com.hptpd.questionnairesurvey.utils;

import com.google.common.collect.Lists;
import com.hptpd.questionnairesurvey.domain.Department;
import com.hptpd.questionnairesurvey.vo.DepartmentVo;
import lombok.Data;

import java.util.List;

/**
 * \* Created with IntelliJ IDEA.
 * \* Date: 2019/9/10
 * \*
 * \* Description:
 * \
 *
 * @author walter_long
 */
public class DepartmentRecursion {
    public DepartmentRecursion(Department department) {
        this.departmentVos = Lists.newLinkedList();
        this.recursionDepartmentUnderParentDepartment(department);
    }

    private DepartmentRecursion() {
    }

    private List<DepartmentVo> departmentVos;
    public List<DepartmentVo> getDepartmentVos() {
        return this.departmentVos;
    }

    private void recursionDepartmentUnderParentDepartment(Department department) {
        departmentVos.add(DepartmentVo.convertDepartment(department));
        List<Department> childDepartments = department.getChildDepartments();
        if (null == childDepartments || childDepartments.isEmpty()) {
            return;
        }
        for (Department tDepartment : childDepartments) {
            recursionDepartmentUnderParentDepartment(tDepartment);
        }
    }
}
